home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.10 Oct 90 / NewToolBox.π / NewToolBox.Lib / LText.Asm < prev    next >
Encoding:
Assembly Source File  |  1989-09-02  |  9.3 KB  |  307 lines  |  [TEXT/KAHL]

  1. ;******************************************
  2. ;*      T E D I T      M A N A G E R      *
  3. ;******************************************
  4.  
  5.  
  6. INCLUDE Library.Txt
  7.  
  8. ;-------------------------------
  9. ; ***   External Definition  ***
  10. ;-------------------------------   
  11.  
  12. XDEF InstalText
  13. XDEF FindText
  14. XDEF DrawTexts
  15. XDEF DeactivateText
  16. XDEF ActivateText
  17.     
  18. ;-------------------------------
  19. ;*******  Text Record  *********
  20. ;-------------------------------
  21.  
  22. ;TERec = Record  {100 bytes}
  23. ;{  0}      destRect : Rect
  24. ;{  8}      viewRect : Rect
  25. ;{ 16}       selRect : Rect
  26. ;{ 24}    lineHeight : -1
  27. ;{ 26}    fontAscent : -1
  28. ;{ 28}      selPoint : Point
  29. ;{ 32}      selStart : INTEGER
  30. ;{ 34}        selEnd : INTEGER
  31. ;{ 36}        active : INTEGER
  32. ;{ 38}     wordBreak : ProcPtr
  33. ;{ 42}      clikLoop : ProcPtr
  34. ;{ 46}     clickTime : LongInt
  35. ;{ 50}      clickLoc : INTEGER
  36. ;{ 52}     caretTime : LongInt
  37. ;{ 56}    caretState : INTEGER
  38. ;{ 58}          just : INTEGER
  39. ;{ 60}      TELength : INTEGER
  40. ;{ 62}         hText : Handle
  41. ;{ 66}     recalBack : INTEGER
  42. ;{ 68}    recalLines : INTEGER
  43. ;{ 70}     clikStuff : INTEGER
  44. ;{ 72}        crOnly : INTEGER
  45. ;{ 74}        txFont : 1/2 Handle
  46. ;{ 76}        txFace : 1/2 Handle
  47. ;{ 78}        txMode : XferMode
  48. ;{ 80}        txSize : -1
  49. ;{ 82}        inPort : GrafPtr
  50. ;{ 86}      highHook : ProcPtr
  51. ;{ 90}     caretHook : ProcPtr
  52. ;{ 94}        nLines : INTEGER
  53. ;{ 96}    lineStarts : Array[0:1] of INTEGER
  54.  
  55. ;-------------------------------
  56. ; ***** Text AuxRecord  ********
  57. ;------------------------------- 
  58.  
  59. ;TEAuxRec = Record  {12 bytes}
  60. ;{0}    TID           :INTEGER            
  61. ;{2}    theText     :TEHandle            
  62. ;{6}    nextText    :TEAuxHandle     
  63.  
  64. ;---------------------------------------------------------------------------    
  65. ;FUNCTION InstalText(textID:INTEGER;whichWindow:WindowPtr):OSErr;
  66. ;---------------------------------------------------------------------------
  67.  
  68. ;-------------------------------
  69. ; Parameters
  70. ;-------------------------------
  71.  
  72. textID            EQU 12
  73. whichWindow       EQU 8
  74.  
  75. ;-------------------------------
  76. ; Local Variables
  77. ;-------------------------------
  78.  
  79. theHandle     EQU -10
  80. theNText      EQU -6
  81. error         EQU -2
  82.  
  83. ;-------------------------------
  84.  
  85. InstalText
  86.     LINK A6,#-10              ;local space
  87.     MOVEM.L A2-A4/D3-D7,-(SP) ;save registers
  88.     MOVE.W noErr,error(A6)    ;
  89.     SUBQ.L #4,SP              ;space for result
  90.     MOVE.L #'TEHD',-(SP)      ;restype is'TEHD'
  91.     MOVE.W textID(A6),-(SP)   ;res ID
  92.     _GetResource              ;
  93.     MOVEA.L (SP)+,A1          ;
  94.     SUBQ.L #2,SP              ;
  95.     _ResError                 ;check for error
  96.     MOVE.W (SP)+,error(A6)    ;
  97.     BNE @0                    ;
  98.     MOVE.L A1,theHandle(A6)   ;save handle
  99.     MOVEA.L (A1),A1           ;
  100.     SUBQ.L #4,SP              ;space for TEHandle 
  101.     PEA teDestRect(A1)        ;
  102.     PEA teViewRect(A1)        ;
  103.     _TEStylNew                ;
  104.     MOVEA.L (SP),A1           ;TEHandle in A1
  105.     MOVE.L A1,theNText(A6)    ;save it
  106.     _TECalText                ;Tech Note #131
  107.     MOVE.L theNText(A6),A1    ;
  108.     MOVE.L (A1),A1            ;
  109.     MOVE.L whichWindow(A6),teGrafPort(A1);
  110.     MOVE.W #TRUE,-(SP)        ;
  111.     MOVE.L theNText(A6),-(SP) ;
  112.     _TEAutoView               ;
  113.     MOVE.L whichWindow(A6),A0;
  114.     MOVE.L WrefCon(A0),A0    ;
  115.     MOVE.L (A0),A0            ;
  116.     MOVE.L WText(A0),A3        ;            
  117.     MOVEA.L (A3),A3         ;
  118.     CMPI.L #NIL,theText(A3) ;is there any text ?
  119.     BEQ @2                  ;no, so add one
  120.     
  121. @4
  122.     CMPI.L #NIL,nextText(A3);another text after ?
  123.     BEQ @3                  ;no,add one (@3) 
  124.     MOVEA.L nextText(A3),A3 ;go to the next one
  125.     MOVEA.L (A3),A3         ;
  126.     BRA @4                  ;
  127.     
  128. @3
  129.     MOVEQ #SizeTEAuxRec,D0  ;storage for new textAuxRec
  130.     _NewHandle              ;
  131.     MOVE.W D0,error(A6)     ;
  132.     BNE @1                  ;if error go @1
  133.     MOVE.L A0,nextText(A3)  ;
  134.     MOVEA.L A0,A3           ;
  135.     MOVEA.L (A3),A3         ;
  136.     MOVE.L theNText(A6),theText(A3);
  137.     MOVE.L #NIL,nextText(A3);
  138.     MOVE.W textID(A6),TID(A3);
  139.     BRA @0                   ;
  140.   
  141. @2  
  142.     MOVE.L theNText(A6),theText(A3);for the first
  143.     MOVE.L #NIL,nextText(A3)       ;text of the list 
  144.     MOVE.W textID(A6),TID(A3)     ; TEAuxRec already
  145.     BRA @0                        ;exists
  146.     
  147. @1
  148.     MOVE.L theNText(A6),-(SP)    ;we can't allocate
  149.     _TEDispose                    ;space for TEAuxRec
  150. @0
  151.     MOVE.W error(A6),D0         ;
  152.     MOVEM.L (SP)+,A2-A4/D3-D7   ;
  153.     UNLK A6                     ;
  154.     MOVE.L (SP)+,A0             ;get return address
  155.     ADD.L #6,SP                 ;clean up the stack
  156.     MOVE.W D0,(SP)              ;push function result
  157.     JMP (A0)                    ;
  158.     
  159. ;---------------------------------------------------------------------------    
  160. ;FUNCTION FindText(thePoint:Point;whichWindow:WindowPtr):TEHandle;
  161. ;---------------------------------------------------------------------------
  162.  
  163. ;-------------------------------
  164. ; Parameters
  165. ;-------------------------------
  166.  
  167. thePoint          EQU 12
  168.  
  169. ;-------------------------------
  170. ; Variables
  171. ;-------------------------------
  172.  
  173. SauvHdl EQU -4
  174.  
  175. ;-------------------------------
  176.  
  177. FindText
  178.     LINK A6,#-4              ;
  179.     MOVEM.L A2-A4/D3-D7,-(SP);
  180.     MOVE.L #NIL,A1           ;
  181.     MOVE.L whichWindow(A6),A0;
  182.     MOVE.L WrefCon(A0),A0    ;
  183.     MOVE.L (A0),A0            ;
  184.     MOVE.L WText(A0),A3        ;begining
  185.     MOVE.L A3,SauvHdl(A6)   ;of text list
  186.     MOVEA.L (A3),A3         ;saved on stack
  187.     CMPI.L #NIL,theText(A3) ;is there any text?
  188.     BEQ @0                  ;no,so go away   
  189. @3 
  190.     MOVEA.L theText(A3),A2  ;
  191.     MOVEA.L (A2),A2         ;
  192.     SUBQ.L #2,SP            ;
  193.     MOVE.L thePoint(A6),-(SP);do we
  194.     PEA teViewRect(A2)       ;click in
  195.     _PtInRect                ;this one ?
  196.     MOVE.L SauvHdl(A6),A3    ;
  197.     MOVE.L (A3),A3           ;
  198.     TST.B (SP)+              ;
  199.     BNE @1                   ;yes ! go @1
  200.     CMPI.L #NIL,nextText(A3) ;no.
  201.     BEQ @0                   ;if no more texts
  202.     MOVEA.L nextText(A3),A3  ;go @0 ,if not...
  203.     MOVE.L A3,SauvHdl(A6)    ;next one !
  204.     MOVEA.L (A3),A3          ;
  205.     BRA @3                   ;   
  206. @1      
  207.        MOVE.L theText(A3),A1    ;"clicked" TEHandle            
  208. @0                             ;in A1 
  209.     MOVEM.L (SP)+,A2-A4/D3-D7 ;
  210.     UNLK A6                   ;
  211.     MOVE.L (SP)+,A0           ;
  212.     ADD.L #8,SP               ;
  213.     MOVE.L A1,(SP)            ;
  214.     JMP (A0)                  ; 
  215.     
  216. ;---------------------------------------------------------------------------    
  217. ;PROCEDURE DrawTexts(whichWindow:WindowPtr);
  218. ;---------------------------------------------------------------------------
  219.  
  220. ;-------------------------------
  221. ; Local Variables
  222. ;-------------------------------
  223.  
  224. TextAuxHdl  EQU -4
  225.  
  226. ;-------------------------------
  227.  
  228. DrawTexts
  229.     LINK A6,#-4                     ;
  230.     MOVEM.L A2-A4/D3-D7,-(SP)       ; 
  231.     MOVE.L whichWindow(A6),A0        ;
  232.     MOVE.L WrefCon(A0),A0            ;
  233.     MOVE.L (A0),A0                    ;
  234.     MOVE.L WText(A0),A3                ;
  235.     MOVE.L A3,TextAuxHdl(A6)        ;
  236.     MOVE.L (A3),A3                  ;
  237.     CMPI.L #NIL,theText(A3)         ;is there text in
  238.     BEQ @0                           ;the window ?    
  239. @3    
  240.     MOVEA.L theText(A3),A0          ;
  241.     MOVEA.L (A0),A0                 ;
  242.     PEA teViewRect(A0)              ;
  243.     MOVE.L theText(A3),-(SP)        ;
  244.     _TEUpdate                       ;draw texts
  245.     MOVE.L TextAuxHdl(A6),A3        ;
  246.     MOVE.L (A3),A3                  ;
  247.     CMPI.L #NIL,nextText(A3)        ;until no more
  248.     BEQ @0                           ;texts in list 
  249.     MOVEA.L nextText(A3),A3         ;
  250.     MOVE.L A3,TextAuxHdl(A6)        ;
  251.     MOVEA.L (A3),A3                 ;
  252.     BRA @3                           ;
  253. @0
  254.     MOVEM.L (SP)+,A2-A4/D3-D7       ;no more
  255.     UNLK A6                         ;texts
  256.     MOVE.L (SP)+,A0                 ;go away.
  257.     ADD.L #4,SP                     ;
  258.     JMP (A0)                        ;    
  259.     
  260. ;---------------------------------------------------------------------------    
  261. ;PROCEDURE DeactivateText(whichWindow:WindowPtr);
  262. ;---------------------------------------------------------------------------
  263.  
  264. DeactivateText
  265.     LINK A6,#0                      ;
  266.     MOVEM.L A2-A4/D3-D7,-(SP)       ;
  267.     MOVEA.L whichWindow(A6),A1      ;
  268.     MOVE.L WRefCon(A1),A1           ;
  269.     MOVE.L (A1),A1                  ;
  270.     MOVE.L WactivTxt(A1),A1         ;
  271.     MOVE.L A1,CurrentText(A5)       ;
  272.     CMPA.L #NIL,A1                  ;
  273.     BEQ @0                            ;
  274.     MOVE.L A1,-(SP)                 ;
  275.     _TEDeactivate                   ;
  276. @0
  277.     MOVEM.L (SP)+,A2-A4/D3-D7       ;
  278.     UNLK A6                         ;
  279.     MOVE.L (SP)+,A0                 ;
  280.     ADD.L #4,SP                     ;
  281.     JMP (A0)                        ;
  282.  
  283. ;--------------------------------------------------------------------------- 
  284. ;PROCEDURE ActivateText(whichWindow:WindowPtr);
  285. ;---------------------------------------------------------------------------  
  286.  
  287. ActivateText
  288.     LINK A6,#0                      ;
  289.     MOVEM.L A2-A4/D3-D7,-(SP)       ;
  290.     MOVEA.L whichWindow(A6),A1      ;
  291.     MOVE.L WRefCon(A1),A1           ;
  292.     MOVE.L (A1),A1                  ;
  293.     MOVE.L WactivTxt(A1),A1         ;
  294.     MOVE.L A1,CurrentText(A5)       ;
  295.     CMPA.L #NIL,A1                  ;
  296.     BEQ @0                            ;
  297.     MOVE.L A1,-(SP)                 ;
  298.     _TEActivate                     ;
  299. @0
  300.     MOVEM.L (SP)+,A2-A4/D3-D7       ;
  301.     UNLK A6                         ;
  302.     MOVE.L (SP)+,A0                 ;
  303.     ADD.L #4,SP                     ;
  304.     JMP (A0)                        ;
  305.      
  306.     
  307. END